From 8e17c8f6f4f487f5f65e6c98cd4fd4634e50622b Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Sun, 26 Jan 2020 04:42:29 -0600 Subject: [PATCH] Checkpoint yahoo work. This gets messy because xml_format really wants C pointers to member functions so we'll probably have to shim in an instance and a fake 'this'. --- CMakeLists.txt | 1 + GPSBabel.pro | 1 + Makefile.in | 2 +- vecs.h | 5 ++- yahoo.cc | 51 ++++++++++++------------ yahoo.h | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 29 deletions(-) create mode 100644 yahoo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a34bbaaf..fc095fc4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,7 @@ set(HEADERS vecs.h xcsv.h xmlgeneric.h + yahoo.h zlib/crc32.h zlib/deflate.h zlib/gzguts.h diff --git a/GPSBabel.pro b/GPSBabel.pro index 89ed1eb3d..c09fa997f 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -146,6 +146,7 @@ HEADERS = \ vecs.h \ xcsv.h \ xmlgeneric.h \ + yahoo.h \ zlib/crc32.h \ zlib/deflate.h \ zlib/gzguts.h \ diff --git a/Makefile.in b/Makefile.in index 90e2fd249..7d1a599e4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1053,7 +1053,7 @@ xol.o: xol.cc defs.h config.h zlib/zlib.h zlib/zconf.h cet.h inifile.h \ gbfile.h session.h src/core/datetime.h src/core/optional.h \ garmin_tables.h jeeps/gpsmath.h jeeps/gpsport.h src/core/file.h \ src/core/xmlstreamwriter.h xmlgeneric.h -yahoo.o: yahoo.cc defs.h config.h zlib/zlib.h zlib/zconf.h cet.h \ +yahoo.o: yahoo.cc yahoo.h defs.h config.h zlib/zlib.h zlib/zconf.h cet.h \ inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \ xmlgeneric.h zlib/adler32.o: zlib/adler32.c zlib/zutil.h zlib/zlib.h zlib/zconf.h \ diff --git a/vecs.h b/vecs.h index 6bb20cd57..eeb020180 100644 --- a/vecs.h +++ b/vecs.h @@ -30,6 +30,7 @@ #include "format.h" #include "ggv_bin.h" #include "gpx.h" +#include "yahoo.h" #include "legacyformat.h" @@ -104,7 +105,7 @@ extern ff_vecs_t nmn4_vecs; #if CSVFMTS_ENABLED extern ff_vecs_t compegps_vecs; #endif // CSVFMTS_ENABLED -extern ff_vecs_t yahoo_vecs; +// extern ff_vecs_t yahoo_vecs; extern ff_vecs_t unicsv_vecs; extern ff_vecs_t gtm_vecs; extern ff_vecs_t gpssim_vecs; @@ -309,7 +310,7 @@ private: #if CSVFMTS_ENABLED LegacyFormat compegps_fmt {compegps_vecs}; #endif // CSVFMTS_ENABLED - LegacyFormat yahoo_fmt {yahoo_vecs}; + YahooFormat yahoo_fmt; LegacyFormat unicsv_fmt {unicsv_vecs}; LegacyFormat gtm_fmt {gtm_vecs}; LegacyFormat gpssim_fmt {gpssim_vecs}; diff --git a/yahoo.cc b/yahoo.cc index 33401370b..60abfb696 100644 --- a/yahoo.cc +++ b/yahoo.cc @@ -19,27 +19,18 @@ */ + #include "defs.h" +#include "yahoo.h" #include "xmlgeneric.h" #include -static Waypoint* wpt_tmp; -static char* as; #define MYNAME "yahoo" -static -QVector yahoo_args = { - { - "addrsep", &as, - "String to separate concatenated address fields (default=\", \")", - ", ", ARGTYPE_STRING, ARG_NOMINMAX, nullptr - }, -}; - -static xg_callback wpt_s, wpt_lat, wpt_lon, wpt_e; -static xg_callback wpt_addr /*, wpt_city, wpt_state, wpt_zip, wpt_country*/; - +// static xg_callback wpt_s, wpt_lat, wpt_lon, wpt_e; +// static xg_callback wpt_addr /*, wpt_city, wpt_state, wpt_zip, wpt_country*/; +#if 0 static xg_tag_mapping gl_map[] = { { wpt_s, cb_start, "/ResultSet/Result" }, { wpt_lat, cb_cdata, "/ResultSet/Result/Latitude" }, @@ -52,54 +43,61 @@ static xg_tag_mapping gl_map[] = { { wpt_e, cb_end, "/ResultSet/Result" }, { nullptr, (xg_cb_type)0, nullptr} }; +#endif -static void -yahoo_rd_init(const QString& fname) +void YahooFormat() {printf("Ctor2\n");} +void +YahooFormat::rd_init(const QString& fname) { xml_init(fname, gl_map, nullptr); } -static void -yahoo_read() +void +YahooFormat::read() { xml_read(); } -static void -yahoo_rd_deinit() +void +YahooFormat::rd_deinit() { xml_deinit(); } -void wpt_s(xg_string, const QXmlStreamAttributes*) +void +YahooFormat::wpt_s(xg_string, const QXmlStreamAttributes*) { wpt_tmp = new Waypoint; } -void wpt_e(xg_string, const QXmlStreamAttributes*) +void +YahooFormat::wpt_e(xg_string, const QXmlStreamAttributes*) { waypt_add(wpt_tmp); wpt_tmp = nullptr; } -void wpt_lat(xg_string args, const QXmlStreamAttributes*) +void +YahooFormat::wpt_lat(xg_string args, const QXmlStreamAttributes*) { wpt_tmp->latitude = args.toDouble(); } -void wpt_lon(xg_string args, const QXmlStreamAttributes*) +void +YahooFormat::wpt_lon(xg_string args, const QXmlStreamAttributes*) { wpt_tmp->longitude = args.toDouble(); } -void wpt_addr(xg_string args, const QXmlStreamAttributes*) +void +YahooFormat::wpt_addr(xg_string args, const QXmlStreamAttributes*) { if (!wpt_tmp->notes.isEmpty()) { wpt_tmp->notes += as; } wpt_tmp->notes += args; } - +#if 0 ff_vecs_t yahoo_vecs = { ff_type_file, { ff_cap_read, ff_cap_none, ff_cap_none }, @@ -115,3 +113,4 @@ ff_vecs_t yahoo_vecs = { , NULL_POS_OPS, nullptr }; +#endif diff --git a/yahoo.h b/yahoo.h new file mode 100644 index 000000000..e4f4645e2 --- /dev/null +++ b/yahoo.h @@ -0,0 +1,103 @@ +/* + Read Yahoo Geocoded files. + + Copyright (C) 2002-2020 Robert Lipe, gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ +#ifndef YAHOO_H_INCLUDED_ +#define YAHOO_H_INCLUDED_ + +#include // for QString +#include // for QStringList +#include + +#include "defs.h" +#include "format.h" // for Format +#include "xmlgeneric.h" // for Format + +class YahooFormat : public Format +{ +public: + YahooFormat() {printf("Ctor\n");} + QVector* get_args() override + { + printf("Getting args\n"); + + return &yahoo_args; + } + + ff_type get_type() const override + { + return ff_type_file; + } + + QVector get_cap() const override { + printf("Getting Cap\n"); + return FF_CAP_RW_ALL; + //return { (ff_cap) ff_cap_read }; + } + + QString get_encode() const override { + return CET_CHARSET_ASCII; + } + + int get_fixed_encode() const override { + return 0; + } + + void rd_init(const QString&) override; + void read() override; + void rd_deinit() override; + +private: + Waypoint* wpt_tmp; + char* as; + + QVector yahoo_args = { + { + "addrsep", &as, + "String to separate concatenated address fields (default=\", \")", + ", ", ARGTYPE_STRING, ARG_NOMINMAX, nullptr + }, + }; + void wpt_s(const QString &, const QXmlStreamAttributes *); + + void wpt_e(const QString &, const QXmlStreamAttributes *); + void wpt_lat(const QString &, const QXmlStreamAttributes *); + void wpt_lon(const QString &, const QXmlStreamAttributes *); + void wpt_addr(const QString &, const QXmlStreamAttributes *); + xg_tag_mapping gl_map[]; + +#if 0 + static xg_tag_mapping gl_map[] = { + { wpt_s, cb_start, "/ResultSet/Result" }, + { wpt_lat, cb_cdata, "/ResultSet/Result/Latitude" }, + { wpt_lon, cb_cdata, "/ResultSet/Result/Longitude" }, + { wpt_addr, cb_cdata, "/ResultSet/Result/Address" }, + { wpt_addr, cb_cdata, "/ResultSet/Result/City" }, + { wpt_addr, cb_cdata, "/ResultSet/Result/State" }, + { wpt_addr, cb_cdata, "/ResultSet/Result/Zip" }, + { wpt_addr, cb_cdata, "/ResultSet/Result/Country" }, + { wpt_e, cb_end, "/ResultSet/Result" }, + { nullptr, (xg_cb_type)0, nullptr} + }; +#endif + + +}; + +#endif // YAHOO_H_INCLUDED_ -- 2.30.2